package com.beiding.sqlbuilder.impl;

import com.beiding.sqlbuilder.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SimpleCompareUnit implements CompareUnit {

    //比价类型
    private CompareType compareType;

    //有序的参数列表
    private List<Parameter> parameters;

    private List<ParameterHolder> parameterHolders;

    public SimpleCompareUnit(CompareType compareType, Parameter... parameters) {
        this(compareType, Arrays.asList(parameters));
    }

    public SimpleCompareUnit(CompareType compareType, List<Parameter> parameters) {
        this.compareType = compareType;
        this.parameters = parameters;
    }

    public SimpleCompareUnit(CompareType compareType) {
        this.compareType = compareType;
        this.parameters = new ArrayList<>();

    }

    public void addParameter(Parameter parameter) {
        this.parameters.add(parameter);
    }

    @Override
    public void build(BuilderContext builderContext) {
        if (parameterHolders == null) {
            parameterHolders = new ArrayList<>();
            for (Parameter parameter : parameters) {
                parameterHolders.add(ConditionUtils.buildParameterHolder(parameter, builderContext.getParameterHandlers()));
            }
        }
    }

    @Override
    public CompareType getType() {
        return compareType;
    }

    @Override
    public List<ParameterHolder> getParameters() {
        return parameterHolders;
    }

}
